package team18.yuejian.Adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.List;

import team18.yuejian.R;
import team18.yuejian.bean.ReviewBean;

public class ReviewAdapter extends RecyclerView.Adapter<ReviewAdapter.ViewHolder>{
    private Context mcontext;
    private List<ReviewBean> mPicList;


    static class ViewHolder extends RecyclerView.ViewHolder{
        CardView cardView;
        LinearLayout mlayout;
        TextView username,content,time;

        public ViewHolder(View view){
            super(view);
            cardView = (CardView) view;
            username = view.findViewById(R.id.Pic_review_username);
            content = view.findViewById(R.id.Pic_review_content);
            time = view.findViewById(R.id.Pic_review_time);
            mlayout = view.findViewById(R.id.Pic_review_layout);

        }
    }

    public ReviewAdapter(List<ReviewBean> picList){
        mPicList = picList;
    }

    @Override
    public ReviewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mcontext == null){
            mcontext = parent.getContext();
        }

        View view = LayoutInflater.from(mcontext).inflate(R.layout.cardview_review_list,parent,false);

        return new ReviewAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ReviewAdapter.ViewHolder holder, int position) {
        ReviewBean reviewBean = mPicList.get(position);
        holder.username.setText(reviewBean.getUname());
        holder.content.setText(reviewBean.getRconment());
        holder.time.setText(reviewBean.getRtime());
    }

    @Override
    public int getItemCount() {
        return mPicList.size();
    }
}
